package com.ews.onlineexchange.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Entity
public class ProfessionRatingRecord extends DataEntity {
	
	/**
	 * 行业部门对中介的考评记录
	 */
	private static final long serialVersionUID = 1L;
	
	private ServiceSupplier	supplier;	
	private String  rateText;                       //填写的评价
		
	private Integer score = 20;      
	private Date  ratingDate;
	private User  ratingUser;
	private Integer year;

	@ManyToOne
	@NotNull
	public ServiceSupplier getSupplier() {
		return supplier;
	}

	public void setSupplier(ServiceSupplier supplier) {
		this.supplier = supplier;
	}

	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getRatingDate() {
		return ratingDate;
	}

	public void setRatingDate(Date ratingDate) {
		this.ratingDate = ratingDate;
	}

	@NotNull
	public String getRateText() {
		return rateText;
	}

	public void setRateText(String rateText) {
		this.rateText = rateText;
	}
	
	@NotNull
	@Min(value = 0)
	@Max(value = 30)
	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}
	@OneToOne(cascade= {CascadeType.MERGE})
	public User getRatingUser() {
		return ratingUser;
	}

	public void setRatingUser(User ratingUser) {
		this.ratingUser = ratingUser;
	}
	
	
	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((rateText == null) ? 0 : rateText.hashCode());
		result = prime * result + ((ratingDate == null) ? 0 : ratingDate.hashCode());
		result = prime * result + ((score == null) ? 0 : score.hashCode());
		result = prime * result + ((year == null) ? 0 : year.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProfessionRatingRecord other = (ProfessionRatingRecord) obj;
		if (rateText == null) {
			if (other.rateText != null)
				return false;
		} else if (!rateText.equals(other.rateText))
			return false;
		if (ratingDate == null) {
			if (other.ratingDate != null)
				return false;
		} else if (!ratingDate.equals(other.ratingDate))
			return false;
		if (score == null) {
			if (other.score != null)
				return false;
		} else if (!score.equals(other.score))
			return false;
		if (year == null) {
			if (other.year != null)
				return false;
		} else if (!year.equals(other.year))
			return false;
		return true;
	}

	
	
	
}
